import server from '@dt/server/dt'

const api = {
  sysUserList: server.api().post('/sa-admin/api/v1/sysUser/selectAll'),
  addSysUser: server.api().post('/sa-admin/api/v1/sysUser/insert'),
  editSysUser: server.api().post('/sa-admin/api/v1/sysUser/update'),
  disableSysUsers: server.api().post('/sa-admin/api/v1/sysUser/disableUsers'),
  updatePwd: server.api().post('/sa-admin/api/v1/bs/noToken/updatePassword')
}

function getSysUserList(info) {
  return api.sysUserList.fetch(info).then((res) => {
    res.list.forEach((item) => {
      item.roleIds = item.roleIds ? item.roleIds.split(',') : []
    })
    return res
  })
}

function addSysUserFun(info) {
  return api.addSysUser.fetch(info)
}

function editSysUser(info) {
  return api.editSysUser.fetch(info)
}

function disableSysUsers(info) {
  return api.disableSysUsers.fetch(info)
}

function updatePwd(info) {
  return api.updatePwd.fetch(info)
}

export default {
  getSysUserList,
  addSysUserFun,
  editSysUser,
  disableSysUsers,
  updatePwd
}
